//
//  ChooseBirthdayView.m
//  FlowerRainGround
//
//  Created by lanou on 16/4/23.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "ChooseBirthdayView.h"

@interface ChooseBirthdayView ()<UIPickerViewDataSource, UIPickerViewDelegate>

@property (nonatomic, strong) UIPickerView *pickerView;
@property (nonatomic, strong) NSMutableArray *yearArray;
@property (nonatomic, strong) NSMutableArray *monthArray;
@property (nonatomic, strong) NSMutableArray *dayArray;
@property (nonatomic, strong) UILabel *titleLabel;
@end



@implementation ChooseBirthdayView


- (NSMutableArray *)yearArray{
    if (_yearArray == nil) {
        _yearArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _yearArray;
}

- (NSMutableArray *)monthArray{
    if (_monthArray == nil) {
        _monthArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _monthArray;
}

- (NSMutableArray *)dayArray{
    if (_dayArray == nil) {
        _dayArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _dayArray;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100, kWidth, 100)];
        self.pickerView.delegate = self;
        self.pickerView.dataSource = self;
        [self viewDidLoad];
        self.pickerView.showsSelectionIndicator = YES;
        [self addSubview:self.pickerView];
        
        //显示请选择性别的button
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((kWidth - 100) / 2, 10, 100, 50)];
        self.titleLabel.text = @"请选择日期";
        self.titleLabel.textAlignment = 1;
        [self addSubview:self.titleLabel];
        
        //显示完成的button
        self.finishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.finishButton.frame = CGRectMake(kWidth - 100, 10, 50, 50);
        [self.finishButton setTitle:@"完成" forState:UIControlStateNormal];
        [self addSubview:self.finishButton];
        
        
    }
    return self;
}


- (void)viewDidLoad
{
    
    for (NSInteger i = 1980; i < 9999; i ++) {
        
       [self.yearArray addObject:[NSString stringWithFormat:@"%ld年", i]];
    }
    for (NSInteger i = 1; i < 13; i ++) {
        [self.monthArray addObject:[NSString stringWithFormat:@"%ld月", i]];
    }
    
    for (NSInteger i = 1; i < 31; i ++) {
        [self.dayArray addObject:[NSString stringWithFormat:@"%ld日", i]];
    }

}

//列数
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 3;
}

//显示一列几个数据
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (component == 0) {
        return self.yearArray.count;
    }
    if (component == 1) {
        return self.monthArray.count;
    }
    if ( component == 2) {
        return self.dayArray.count;
    }
    return 0;
    
}


//返回当前行的值
- (NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    if (component == 0) {
        self.years =  [self.yearArray objectAtIndex:row];
        return self.years;
    }
    if (component == 1) {
        self.month =  [self.monthArray objectAtIndex:row];
        return self.month;
    }
    if ( component == 2) {
        self.day =  [self.dayArray objectAtIndex:row];
        return self.day;
    }
    return nil;
   
}




- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    
}





/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
